<template></template>
<script setup>
/* 地图点击事件-弹窗显示查询的事件/监控视频/警务室信息 */
import { ref, getCurrentInstance, onMounted } from "vue";
const { proxy } = getCurrentInstance();

import { Query } from "@/zondyTools/mapgis-api/Query";
import { usePopupStore } from "@/stores/popupStore";
import { useRoute } from "vue-router";
const route = useRoute();

const { showPopup, showVideo,  showStatus, hideStatus} = usePopupStore();
let $map = null;

onMounted(() => {
  $map = proxy.$map;

  /* 查询-事件-图层 */
  $map.on("click", (e) => {
    
    const position = e.coordinate;
    const service = {
      name: "guanggu",
      layerId: 2,
    };
    function success(res) {
      if (res == null) {
        return;
      }
      //console.log(res[0].getId())
      const attr = res[0].values_.getProperties();
      /* 设置服务器获取到的处理状态和图层id */
      showStatus({message:attr["处理状态"],fid:res[0].getId()});
      
      /* 处理查询结果  --根据用户类型过滤数据 */
      function handleData(data) {
        if (route.query.type == "traffic" || route.query.type == "admin") {
          delete data.mpLayer;
        } else {
          delete data.mpLayer;
          delete data["驾驶员"];
          delete data["车牌号"];
        }

        delete data["处理状态"];
        return data;
      }

      const content = handleData(attr);

      /* 展示popup弹窗 */
      showPopup({ position, content });
    }
    /* 根据鼠标点击位置查询事件图层 */
    Query.queryByPnt({ service, position, success });
  });

  /* 查询-警务室-图层 */
  $map.on("click", (e) => {
    const position = e.coordinate;
    const service = {
      name: "guanggu",
      layerId: 4,
    };
    function success(res) {
      if (res == null ) {
        return;
      }
      hideStatus();
      /* 处理查询结果 */
      function handleData(data) {
        delete data.mpLayer;
        return data;
      }
      const content = handleData(res[0].values_.getProperties());

      /* 展示popup弹窗 */
      showPopup({ position, content });
    }

    /* 根据鼠标点击位置查询警务室图层 */
    Query.queryByPnt({ service, position, success });
  });

  /* 查询-监控-图层 */
  $map.on("click", (e) => {
    //console.log(e.coordinate);
    const position = e.coordinate;
    const service = {
      name: "guanggu",
      layerId: 3,
    };
    function success(res) {
      if (res == null || route.query.type == "common") {
        return;
      }

      /* 让popup弹窗显示监控视频 */
      showVideo(position);
    }
    /* 根据鼠标点击位置查询监控图层 */
    Query.queryByPnt({ service, position, success });
  });
});
</script>
<style scoped></style>
